package com.zhuoli.service.springboot.mybatis.transaction.controller;

import com.zhuoli.service.springboot.mybatis.transaction.common.request.CreateUserRequest;
import com.zhuoli.service.springboot.mybatis.transaction.service.UserControllerService;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author: zhuoli
 * @Date: 2018/8/2 11:17
 * @Description:
 */
@AllArgsConstructor
@RestController
@RequestMapping(value = "/user")
public class UserController {
    private UserControllerService userControllerService;

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public ResponseEntity createUser(@Valid @RequestBody CreateUserRequest createUserRequest) {
        userControllerService.createUser(createUserRequest);
        return ResponseEntity.status(HttpStatus.OK).body("success");
    }

    @RequestMapping(value = "/create_annotation", method = RequestMethod.POST)
    public ResponseEntity createUserWithAnnotation(@Valid @RequestBody CreateUserRequest createUserRequest) {
        userControllerService.createUserWithAnnotation(createUserRequest);
        return ResponseEntity.status(HttpStatus.OK).body("success");
    }
}